package com.zhdl.modules.wallpulley.service.impl;

import com.project.common.service.impl.BaseServiceImpl;
import com.zhdl.modules.wallpulley.entity.*;
import com.zhdl.modules.wallpulley.repository.WallPulleyWarnInfoDao;
import com.zhdl.modules.wallpulley.service.WallPulleyWarnInfoService;
import com.zhdl.modules.wallpulley.web.req.WallPulleyWarnInfoReq;
import com.zhdl.modules.wallpulley.web.resp.WallPulleyWarnInfoResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Slf4j
@Service
public class WallPulleyWarnInfoServiceImpl extends BaseServiceImpl<Integer, WallPulleyWarnInfo, WallPulleyWarnInfoDao> implements WallPulleyWarnInfoService {


    @Resource
    private WallPulleyWarnInfoDao wallPulleyWarnInfoDao;

    @Override
    public int saveWarnInfos(WallPulleyWarnInfo resp) {
        WallPulleyWarnInfo wallPulleyWarnInfo = new WallPulleyWarnInfo();
        wallPulleyWarnInfo.setWarnInfo(resp.getWarnInfo());
        wallPulleyWarnInfo.setCreateDate(resp.getCreateDate());
        WallPulleyWarnInfo save = wallPulleyWarnInfoDao.save(wallPulleyWarnInfo);
        return save.getId();
    }

    @Override
    public WallPulleyWarnInfo findWarnInfoById(int id) {
        Optional<WallPulleyWarnInfo> byId = wallPulleyWarnInfoDao.findById(id);
        WallPulleyWarnInfo parameterSettings = new WallPulleyWarnInfo();
        if (byId.isPresent()) {
            parameterSettings = byId.get();
        }
        return parameterSettings;
    }

    @Override
    public List<WallPulleyWarnInfo> findAllWarnInfo() {
        return wallPulleyWarnInfoDao.findAll();
    }

    @Override
    public WallPulleyWarnInfo warnReqToEntity(WallPulleyWarnInfoReq warnInfoReq){
        WallPulleyWarnInfo wallPulleyWarnInfo = new WallPulleyWarnInfo();
        wallPulleyWarnInfo.setWarnInfo(warnInfoReq.getWarnInfo());
        return wallPulleyWarnInfo;
    }

    @Override
    public WallPulleyWarnInfoResp warnEntityToResp(WallPulleyWarnInfo warnInfo){
        WallPulleyWarnInfoResp wallPulleyWarnInfoResp = new WallPulleyWarnInfoResp();
        wallPulleyWarnInfoResp.setWarnInfo(warnInfo.getWarnInfo());
        return wallPulleyWarnInfoResp;
    }

    @Override
    public List<WallPulleyWarnInfo> warnReqsToEntity(List<WallPulleyWarnInfoReq> warnInfoReqs){
        List<WallPulleyWarnInfo> wallPulleyWarnInfos = new ArrayList<>();
        for (WallPulleyWarnInfoReq warnInfoReq : warnInfoReqs) {
            WallPulleyWarnInfo warnInfo = new WallPulleyWarnInfo();
            warnInfo.setWarnInfo(warnInfoReq.getWarnInfo());

            wallPulleyWarnInfos.add(warnInfo);
        }
        return wallPulleyWarnInfos;
    }

    @Override
    public List<WallPulleyWarnInfoResp> warnEntityToResps(List<WallPulleyWarnInfo> warnInfos) {
        List<WallPulleyWarnInfoResp> wallPulleyWarnInfoResps = new ArrayList<>();
        for (WallPulleyWarnInfo warnInfo : warnInfos) {
            WallPulleyWarnInfoResp wallPulleyWarnInfoResp = new WallPulleyWarnInfoResp();
            wallPulleyWarnInfoResp.setWarnInfo(warnInfo.getWarnInfo());

            wallPulleyWarnInfoResps.add(wallPulleyWarnInfoResp);
        }
        return wallPulleyWarnInfoResps;
    }
}